
var salary_data = [];

$(function() {
	
	_change("input[id^='name_s']:visible", "select[id^='name_t']:visible");
});

var SalaryFile = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否提交？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];

				var body = { };
				
				body.emp = form.emp.value;
				
				body.name = form.name.value;
				body.type = form.type.value;
				body.date = form.date.value;
				body.content = form.content.value;
				
				// body.item = data;
				body.item = $.toJSON(data);

				$(this).dialog("close");

				$.post('finance.php?do=SalaryFile.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	dialog_import: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"导入": function() {
				if (!confirm("确认是否导入？")) {
					return false;
				}
				
				$('#userfile').uploadify('upload');
			}
		});

		dialog_add(url, title, xy);
	},
	
	dialog_next: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"导入": function() {
				if (!confirm("确认是否导入？")) {
					return false;
				}
				
				$('#userfile').uploadify('upload');
			}
		});

		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status, emp) {
		$.cookie('id_', id);
		$.cookie('emp_', emp);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'finance.php?do=SalaryFile.edit&id=' + id;
		var c2 = 'finance.php?do=SalaryFile.view&id=' + id;
		
		var c4 = 'finance.php?do=SalaryFile.import&id=' + id;
		
		var a1 = ['编辑信息', 'url', 'SalaryFile.dialog_edit_', '700x450'];	
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x420'];
		
		var a4 = ['导入信息', 'url', 'SalaryFile.dialog_import', '700x450'];

		var s = c1 + ", " + c2 + ", " + c4;

		return this.popup_(e, [a1, a2, a4], s);
	},

	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		var emp = $.cookie('emp_');
		
		var c2 = 'finance.php?do=SalaryFile.upload&id=' + id;
		var a2 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		var ss = 'finance.php?do=SalaryFile.ss&id=' + id;
		var bb = ['修改状态', 'url', 'SalaryFile.dialog_ss', '400x200'];
		
		s += ", " + c2 + ", " + ss;
		
		a.push(a2);
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		result = Common.result();
		$.getJSON('finance.php?do=SalaryFile.audit&item=145', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'finance.php?do=SalaryFile.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.emp = form.emp.value;
				body.date = form.date.value;
				
				body.type = form.type.value;
				body.name = form.name.value;
				body.content = form.content.value;
				
				body.item = $.toJSON(data);
				// body.item = data;
				
				$(this).dialog("close");
	
				var url = 'finance.php?do=SalaryFile.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var p2 = $.cookie('p2');
		// alert(p2);
		
		var c1 = 'finance.php?do=SalaryFile.delete' + p2;
		
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		
		var s = c1;
		var a = [a1];
		
		var c9a = 'finance.php?do=SalaryFile.xls&' + p2;
		
		var a9a = ['导出Excel', 'url', 'jswin', '1024x768'];
		
		s += ", " + c9a;
		
		a.push(a9a);
		
		return popup(e, a, s);
	}
};
